//
//  OMOrder.m
//  OMENGO
//
//  Created by 梁尚嘉 on 2016/12/27.
//  Copyright © 2016年 Kamfat. All rights reserved.
//

#import "OMOrder.h"

@implementation OMOrderItem
+ (NSDictionary *)mj_replacedKeyFromPropertyName
{
    return @{@"image":@"thumbnail"};
}

- (NSString *)brand
{
    return [_brand stringByReplacingOccurrencesOfString:@"null" withString:@" "];
}

- (NSString *)unit
{
    return [_unit stringByReplacingOccurrencesOfString:@"null" withString:@""];
}
@end


@implementation OMOrder
+ (NSDictionary *)mj_objectClassInArray
{
    return @{
             @"orderItems":[OMOrderItem class],
             @"refunds":[OMRefund class],
             };
}

+ (NSString *)mj_replacedKeyFromPropertyName121:(NSString *)propertyName
{
    return [propertyName mj_underlineFromCamel];
}

- (NSString *)desc
{
    if (!_desc) {
        NSMutableString *descTemp = [[NSMutableString alloc]initWithString:@""];
        for (OMOrderItem *item in self.orderItems) {
            NSMutableString *detailTemp = [[NSMutableString alloc]initWithString:@""];
            if (descTemp.length) {
                [detailTemp appendString:@"，"];
            }
            if (item.brand.length) {
                [detailTemp appendFormat:@"【%@】",item.brand];
            }
            [detailTemp appendString:item.name];
            if (item.unit.length) {
                [detailTemp appendFormat:@"%@",item.unit];
            }
            [detailTemp appendFormat:@" x%lu",(unsigned long)item.quantity];
            if (detailTemp.length) {
                [descTemp appendString:detailTemp];
            }
        }
        _desc = descTemp;
    }
    return _desc;
}

@end
